<template>
  <div class="board-column">
    <draggable :list="list" v-bind="$attrs" class="board-column-content" :set-data="setData">
      <div v-for="(item, index) in list" :key="item.id" class="board-item" :style="item.show?{display: 'inherit'}:{display: 'none'}" @click="activeClick(item, index)">
        <div class="board-name">
          <span>{{ item.title }}</span>
        </div>
        <el-image :src="item.src" class="board-image">
          <div slot="error" class="image-slot">
            <i class="el-icon-picture-outline" />
          </div>
        </el-image>
      </div>
    </draggable>
  </div>
</template>

<script>
import draggable from 'vuedraggable'
import { bus } from '@/main'

export default {
  name: 'DragKanbanDemo',
  components: {
    draggable
  },
  props: {
    headerText: {
      type: String,
      default: 'Header'
    },
    options: {
      type: Object,
      default() {
        return {}
      }
    },
    list: {
      type: Array,
      default() {
        return []
      }
    },
    imageTextType: {
      type: String,
      default() {
        return 'single'
      }
    }
  },
  data() {
    return {
      Index: 0
    }
  },
  computed: {
    srcImg(val) {
      // const img = require(val)
      console.log(val)
      // return
    }
  },
  mounted() {
    // 设置第一个图文的选中状态
    setTimeout(() => {
      this.activeClick(this.list[0], 0)
    }, 1000)
  },
  methods: {
    setData(dataTransfer) {
      dataTransfer.setData('Text', '')
    },
    // 选中状态
    activeClick(data, index) {
      for (const i in this.list) {
        const name = document.getElementsByClassName('board-item')[i].className
        if (name.indexOf('active') > 0) {
          document.getElementsByClassName('board-item')[i].classList.remove('active')
        }
      }
      document.getElementsByClassName('board-item')[index].classList.add('active')
      bus.$emit('imageTextChangeDetail', { key: data.dataID, type: '' })
    }
  }
}
</script>
<style lang="scss" scoped>
.board-column {
  min-width: 3rem;
  min-height: 1rem;
  height: auto;
  overflow: hidden;
  border-radius: 3px;

  .board-column-header {
    height: 0.5rem;
    line-height: 0.5rem;
    overflow: hidden;
    padding: 0 0.2rem;
    text-align: center;
    background: #333;
    color: #fff;
    border-radius: 3px 3px 0 0;
  }

  .board-column-content {
    height: auto;
    overflow: hidden;
    min-height: 0.6rem;
    display: flex;
    justify-content: flex-start;
    flex-direction: column;
    align-items: center;
    padding: 0.05rem;
    .board-item {
      cursor: pointer;
      width: 100%;
      min-height: 0.5rem;
      background-color: #fff;
      text-align: left;
      padding: 0.1rem;
      box-sizing: border-box;
      box-shadow: 0px 1px 3px 0 rgba(0, 0, 0, 0.2);
      position: relative;
      overflow: hidden;
      margin-bottom: 0.2rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .board-image {
        width: 0.6rem;
        height: 0.6rem;
        >>>.image-slot {
          i {
            color: #ccc;
            font-size: 0.6rem;
            line-height: 0.6rem;
          }
        }
      }
      .board-name {
        color: #000;
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        position: relative;
        .boardDelete {
          position: absolute;
          right: 0.1rem;
          top: 0.05rem;
        }
      }
    }
    .active {
      border: 2px solid #409eff;
      .board-image {
        width: 100%;
        height: 2rem;
        >>>.image-slot {
          width: 100%;
          height: 100%;
          text-align: center;
          i {
            color: #ccc;
            font-size: 1rem;
            line-height: 1.5rem;
          }
        }
      }
      .board-name {
        position: absolute;
        left: 0.1rem;
        right: 0.1rem;
        bottom: 0.15rem;
        height: 0.5rem;
        line-height: 0.5rem;
        text-align: center;
        background: rgba(0,0,0,.7);
        color: #fff;
        z-index: 1;
        padding: 0 0.2rem;
      }
    }
  }
}
</style>

